/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import dao.DaoClientes;
import dao.DaoFilmes;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;


public class TelaAlugar extends javax.swing.JInternalFrame {
    DaoClientes daoClientes  = new DaoClientes();
    boolean clienteSelecionado = false;
    DaoFilmes daoFilmes = new DaoFilmes();
    Vector idFilmes = new Vector();
    int produtos = 0;
    String [] codProdutos;

    /**
     * Creates new form TelaAlugar
     */
    public TelaAlugar() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelBuscaCliente = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        comboProcuraCliente = new javax.swing.JComboBox();
        jTextFieldBuscaCliente = new javax.swing.JTextField();
        consultarCliente = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableClientes = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jPanelBuscaFilme = new javax.swing.JPanel();
        jTextFieldBuscaFilme = new javax.swing.JTextField();
        jButtonAdicionaFilmeReserva = new javax.swing.JButton();
        comboBuscaFilme = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableFilmes = new javax.swing.JTable();
        consultarFilme = new javax.swing.JButton();
        jPanelCarrinho = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jButtonAdicionaFilmeReserva2 = new javax.swing.JButton();
        jButtonAdicionaFilmeReserva4 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        nomeClienteAlugar = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtCarrinho = new javax.swing.JTextArea();
        jSeparator3 = new javax.swing.JSeparator();

        setClosable(true);
        setIconifiable(true);
        setResizable(true);
        setTitle("Locações");
        setToolTipText("");
        setMaximumSize(new java.awt.Dimension(1300, 748));
        setPreferredSize(new java.awt.Dimension(1217, 700));
        getContentPane().setLayout(null);

        jLabel3.setFont(new java.awt.Font("Vrinda", 1, 18)); // NOI18N
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/1Cliente.png"))); // NOI18N
        jLabel3.setText("Clientes:");

        comboProcuraCliente.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        comboProcuraCliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Código", "Nome" }));
        comboProcuraCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboProcuraClienteActionPerformed(evt);
            }
        });

        jTextFieldBuscaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldBuscaClienteActionPerformed(evt);
            }
        });

        consultarCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/lupa.png"))); // NOI18N
        consultarCliente.setToolTipText("Procurar Cliente");
        consultarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                consultarClienteActionPerformed(evt);
            }
        });

        tableClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(tableClientes);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BuscaCliente.png"))); // NOI18N
        jButton1.setText("Selecionar Cliente");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelBuscaClienteLayout = new javax.swing.GroupLayout(jPanelBuscaCliente);
        jPanelBuscaCliente.setLayout(jPanelBuscaClienteLayout);
        jPanelBuscaClienteLayout.setHorizontalGroup(
            jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                        .addComponent(comboProcuraCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldBuscaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(consultarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 396, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelBuscaClienteLayout.setVerticalGroup(
            jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBuscaClienteLayout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelBuscaClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(comboProcuraCliente, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(consultarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldBuscaCliente, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        getContentPane().add(jPanelBuscaCliente);
        jPanelBuscaCliente.setBounds(0, 0, 420, 270);

        jButtonAdicionaFilmeReserva.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Mais.png"))); // NOI18N
        jButtonAdicionaFilmeReserva.setText("Adiciona Filme ao Carrinho");
        jButtonAdicionaFilmeReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAdicionaFilmeReservaActionPerformed(evt);
            }
        });

        comboBuscaFilme.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        comboBuscaFilme.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Código", "Nome" }));
        comboBuscaFilme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBuscaFilmeActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Vrinda", 1, 18)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Filme.png"))); // NOI18N
        jLabel1.setText("Filmes:");

        tableFilmes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tableFilmes);

        consultarFilme.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/lupa.png"))); // NOI18N
        consultarFilme.setToolTipText("Procurar Cliente");
        consultarFilme.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                consultarFilmeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelBuscaFilmeLayout = new javax.swing.GroupLayout(jPanelBuscaFilme);
        jPanelBuscaFilme.setLayout(jPanelBuscaFilmeLayout);
        jPanelBuscaFilmeLayout.setHorizontalGroup(
            jPanelBuscaFilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBuscaFilmeLayout.createSequentialGroup()
                .addGroup(jPanelBuscaFilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelBuscaFilmeLayout.createSequentialGroup()
                        .addGroup(jPanelBuscaFilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(comboBuscaFilme, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldBuscaFilme, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(consultarFilme, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 522, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAdicionaFilmeReserva))
                .addGap(0, 28, Short.MAX_VALUE))
        );
        jPanelBuscaFilmeLayout.setVerticalGroup(
            jPanelBuscaFilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelBuscaFilmeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBuscaFilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelBuscaFilmeLayout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelBuscaFilmeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldBuscaFilme, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboBuscaFilme, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)))
                    .addComponent(consultarFilme, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(140, 140, 140)
                .addComponent(jButtonAdicionaFilmeReserva)
                .addGap(79, 79, 79))
        );

        getContentPane().add(jPanelBuscaFilme);
        jPanelBuscaFilme.setBounds(451, 0, 550, 560);

        jLabel4.setFont(new java.awt.Font("Vrinda", 1, 18)); // NOI18N
        jLabel4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tiago\\Dropbox\\ProjetoIntegrador\\ProjetoVideoLocadora\\img\\icones\\Carinho.png")); // NOI18N
        jLabel4.setText("Carrinho:");

        jButtonAdicionaFilmeReserva2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Cancela.png"))); // NOI18N
        jButtonAdicionaFilmeReserva2.setText("Limpar Carrinho");
        jButtonAdicionaFilmeReserva2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAdicionaFilmeReserva2ActionPerformed(evt);
            }
        });

        jButtonAdicionaFilmeReserva4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Salvar.png"))); // NOI18N
        jButtonAdicionaFilmeReserva4.setText("Finalizar Locação");
        jButtonAdicionaFilmeReserva4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAdicionaFilmeReserva4ActionPerformed(evt);
            }
        });

        jLabel5.setText("Cliente :");

        nomeClienteAlugar.setEnabled(false);

        txtCarrinho.setColumns(20);
        txtCarrinho.setRows(5);
        jScrollPane4.setViewportView(txtCarrinho);

        javax.swing.GroupLayout jPanelCarrinhoLayout = new javax.swing.GroupLayout(jPanelCarrinho);
        jPanelCarrinho.setLayout(jPanelCarrinhoLayout);
        jPanelCarrinhoLayout.setHorizontalGroup(
            jPanelCarrinhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCarrinhoLayout.createSequentialGroup()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nomeClienteAlugar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanelCarrinhoLayout.createSequentialGroup()
                .addComponent(jScrollPane4)
                .addContainerGap())
            .addGroup(jPanelCarrinhoLayout.createSequentialGroup()
                .addComponent(jButtonAdicionaFilmeReserva2, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonAdicionaFilmeReserva4, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(70, Short.MAX_VALUE))
        );
        jPanelCarrinhoLayout.setVerticalGroup(
            jPanelCarrinhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCarrinhoLayout.createSequentialGroup()
                .addGroup(jPanelCarrinhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(nomeClienteAlugar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelCarrinhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAdicionaFilmeReserva2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAdicionaFilmeReserva4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(65, 65, 65))
        );

        getContentPane().add(jPanelCarrinho);
        jPanelCarrinho.setBounds(0, 269, 420, 360);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        getContentPane().add(jSeparator3);
        jSeparator3.setBounds(429, 0, 10, 690);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void comboProcuraClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboProcuraClienteActionPerformed

    }//GEN-LAST:event_comboProcuraClienteActionPerformed

    private void jTextFieldBuscaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldBuscaClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldBuscaClienteActionPerformed

    private void consultarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarClienteActionPerformed
          
            this.prencherTabelaClientes();
 
    }//GEN-LAST:event_consultarClienteActionPerformed
    private void prencherTabelaClientes(){

        ResultSet rs;
        try {
            rs = daoClientes.retornaCliente(jTextFieldBuscaCliente.getText(), comboProcuraCliente.getSelectedIndex());
             ResultSetMetaData rsmetadata = rs.getMetaData();
        
        //nº de colunas
        int columns = rsmetadata.getColumnCount();
        
        DefaultTableModel dtm = new DefaultTableModel();
        
        Vector colunsName = new Vector();
        Vector dataRows = new Vector();
        
        for (int i = 1; i < columns; i++) {
            colunsName.addElement(rsmetadata.getColumnName(i));
        }
        dtm.setColumnIdentifiers(colunsName);
        while(rs.next()){
            dataRows = new Vector();
            for(int j = 1 ; j < columns;j++){
                dataRows.addElement(rs.getString(j));
            }
            dtm.addRow(dataRows);
            
        } 
            this.tableClientes.setModel(dtm);
            tableClientes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        } catch (SQLException ex) {
            Logger.getLogger(TelaAlugar.class.getName()).log(Level.SEVERE, null, ex);
        }
       
           
          
                
       
    }
        
    
    
    
    
    private void jButtonAdicionaFilmeReserva4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAdicionaFilmeReserva4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonAdicionaFilmeReserva4ActionPerformed

    private void comboBuscaFilmeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBuscaFilmeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboBuscaFilmeActionPerformed

    private void consultarFilmeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarFilmeActionPerformed
        try {
            this.preecheTableFilmes();
        } catch (SQLException ex) {
            Logger.getLogger(TelaAlugar.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_consultarFilmeActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      this.clienteSelecionado = true;
        
            String idClienteSelecionado = tableClientes.getValueAt(tableClientes.getSelectedRow(), 0).toString();
            String nomeClienteSelecionado = tableClientes.getValueAt(tableClientes.getSelectedRow(), 1).toString();
       
            this.nomeClienteAlugar.setText(nomeClienteSelecionado);
           
           
      
        
    
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButtonAdicionaFilmeReservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAdicionaFilmeReservaActionPerformed
        if(this.clienteSelecionado){
                     
            String codFilme = tableFilmes.getValueAt(tableFilmes.getSelectedRow(), 0).toString();
            String tituloFilme = tableFilmes.getValueAt(tableFilmes.getSelectedRow(), 1).toString();
           
            this.txtCarrinho.setText(this.txtCarrinho.getText()+"\n-- Cod.Filme: "+codFilme+"   Titulo: "+tituloFilme);
            this.codProdutos[this.produtos] = codFilme;
           
        }else{
            JOptionPane.showMessageDialog(this, "Primeiro Selecione o Cliente!");
        }
    }//GEN-LAST:event_jButtonAdicionaFilmeReservaActionPerformed

    private void jButtonAdicionaFilmeReserva2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAdicionaFilmeReserva2ActionPerformed
        this.txtCarrinho.setText(null);
        this.codProdutos = null;
        
    }//GEN-LAST:event_jButtonAdicionaFilmeReserva2ActionPerformed

        public void preecheTableFilmes() throws SQLException {
        ResultSet rsFilmes =  daoFilmes.retornFilmes(jTextFieldBuscaFilme.getText(), comboBuscaFilme.getSelectedIndex());
        
        ResultSetMetaData rsmetadata = rsFilmes.getMetaData();
        
        //nº de colunas
        int columns = rsmetadata.getColumnCount();
        
        DefaultTableModel dtm = new DefaultTableModel();
        
        Vector colunsName = new Vector();
        Vector dataRows = new Vector();
        
        for (int i = 1; i < columns; i++) {
            colunsName.addElement(rsmetadata.getColumnName(i));
        }
        dtm.setColumnIdentifiers(colunsName);
        while(rsFilmes.next()){
            dataRows = new Vector();
            for(int j = 1 ; j < columns;j++){
                dataRows.addElement(rsFilmes.getString(j));
            }
            dtm.addRow(dataRows);
            
        } 
            this.tableFilmes.setModel(dtm);
            tableFilmes.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            
          
                
       
    }
    
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboBuscaFilme;
    private javax.swing.JComboBox comboProcuraCliente;
    private javax.swing.JButton consultarCliente;
    private javax.swing.JButton consultarFilme;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonAdicionaFilmeReserva;
    private javax.swing.JButton jButtonAdicionaFilmeReserva2;
    private javax.swing.JButton jButtonAdicionaFilmeReserva4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanelBuscaCliente;
    private javax.swing.JPanel jPanelBuscaFilme;
    private javax.swing.JPanel jPanelCarrinho;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextFieldBuscaCliente;
    private javax.swing.JTextField jTextFieldBuscaFilme;
    private javax.swing.JTextField nomeClienteAlugar;
    private javax.swing.JTable tableClientes;
    private javax.swing.JTable tableFilmes;
    private javax.swing.JTextArea txtCarrinho;
    // End of variables declaration//GEN-END:variables
}
